package com.wangsd.web.sys.controller;


import com.alibaba.fastjson.JSONArray;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.sys.entity.Area;
import com.wangsd.web.sys.service.AreaService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-10-28
 */
@RestController
@RequestMapping("/sys/area")
public class AreaController {
    @Autowired
    AreaService areaService;

    @ApiOperation(value = "通过父级id查询地区信息", notes = "通过父级id查询地区信息", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/selectByParentId/{parentId}", method = RequestMethod.GET)
    public Result selectByParentId(@ApiParam(value = "父级区域id", required = true) @PathVariable("parentId") String parentId) {
        List<Area> areas = areaService.selectByParentId(parentId);
        return Result.success(areas);
    }

    @ApiOperation(value = "通过查询地区级联数据结构", notes = "通过查询地区级联数据结构", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/selectAllArea", method = RequestMethod.GET)
    public Result selectAllArea() {
        JSONArray jsonArray = areaService.selectAllArea();
        return Result.success(jsonArray);
    }
}

